/*
 * @Description: 发布管理
 * @Author: iamsmiling
 * @Date: 2021-06-11 10:37:52
 * @LastEditTime: 2021-06-13 17:58:38
 */
import 'package:credit_business_circle/R/R.dart';
import 'package:credit_business_circle/common_kit/color_kit.dart';
import 'package:credit_business_circle/domain/local/topic/topic_entity.dart';
import 'package:credit_business_circle/domain/remote/topic/topic_entity.dart';
import 'package:credit_business_circle/pages/mine/children/my_publish/my_publish_controller.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class MyPublishPage extends GetView<MyPublishController> {
  const MyPublishPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("发布管理"),
        elevation: .5,
        actions: [
          TextButton.icon(
              onPressed: () {},
              icon: Image.asset(R.image.funnel),
              label: Text(
                "筛选",
                style:
                    TextStyle(fontSize: R.dimen.sp12, color: R.color.ff666666),
              ))
        ],
        bottom: PreferredSize(
          preferredSize: Size.fromHeight(R.dimen.dp56),
          child: DefaultTextStyle(
            style: TextStyle(
                fontSize: R.dimen.sp12,
                color: R.color.ff111111,
                fontWeight: FontWeight.w500),
            child: Container(
              alignment: Alignment.center,
              padding: EdgeInsets.only(
                  left: R.dimen.dp11,
                  right: R.dimen.dp11,
                  bottom: R.dimen.dp18),
              child: Row(
                children: [
                  Text("变色卡: 10 刷新卡: 20 置顶卡: 16 头条卡: 36"),
                  Spacer(),
                  Container(
                    alignment: Alignment.center,
                    padding: EdgeInsets.symmetric(
                        horizontal: R.dimen.dp16, vertical: R.dimen.dp4),
                    decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(R.dimen.sp20),
                        gradient: LinearGradient(
                            colors: [R.color.ff33cda0, R.color.ff25b48a])),
                    child: Text(
                      "购买",
                      style: TextStyle(
                          color: R.color.ffffffff, fontSize: R.dimen.sp13),
                    ),
                  )
                ],
              ),
            ),
          ),
        ),
      ),
      body: CustomScrollView(
        slivers: [
          SliverList(
              delegate:
                  SliverChildBuilderDelegate((BuildContext context, int i) {
            TopicPublishmentEntity topic = controller.topics[i];

            return Container(
              margin: EdgeInsets.all(R.dimen.dp10),
              decoration: BoxDecoration(
                  color: R.color.ffffffff,
                  border: Border.all(color: R.color.ffdddddd, width: .5),
                  borderRadius: BorderRadius.circular(R.dimen.sp8)),
              padding: EdgeInsets.only(top: R.dimen.dp24, bottom: R.dimen.dp20),
              child: Column(
                children: [
                  Container(
                    padding: EdgeInsets.only(
                        left: R.dimen.dp20, right: R.dimen.dp20),
                    child: Text.rich(TextSpan(
                        text: topic.title,
                        style: TextStyle(
                            fontSize: R.dimen.sp14,
                            color: R.color.ff333333,
                            fontWeight: FontWeight.w600),
                        children: [
                          WidgetSpan(
                            child: Image.asset(R.image.imgTag),
                          ),
                          TextSpan(
                              text: "  信息编号：${topic.no}",
                              style: TextStyle(
                                  fontSize: R.dimen.sp12,
                                  fontWeight: FontWeight.normal))
                        ])),
                  ),
                  Container(
                    margin: EdgeInsets.only(
                      top: R.dimen.dp20,
                      left: R.dimen.dp20,
                    ),
                    child: Row(
                      children: [
                        for (TopicTagEntity tag in topic.tags)
                          Container(
                            padding: EdgeInsets.symmetric(
                                vertical: R.dimen.dp4, horizontal: R.dimen.dp6),
                            decoration: BoxDecoration(
                                color: tag.color,
                                borderRadius:
                                    BorderRadius.circular(R.dimen.sp3)),
                            margin: EdgeInsets.only(right: R.dimen.dp9),
                            child: Text(
                              tag.text,
                              style: TextStyle(
                                  fontSize: R.dimen.sp11,
                                  color: R.color.ff666666),
                            ),
                          ),
                        Spacer(),
                        Container(
                          padding: EdgeInsets.symmetric(
                              horizontal: R.dimen.dp13, vertical: R.dimen.dp5),
                          decoration: BoxDecoration(
                            borderRadius: BorderRadius.only(
                                topLeft: Radius.circular(R.dimen.sp5),
                                bottomLeft: Radius.circular(R.dimen.sp5)),
                            color: ColorKit.fromHex(topic.status.color),
                          ),
                          child: Text(
                            "${topic.status.name}",
                            style: TextStyle(
                                fontSize: R.dimen.sp12,
                                color: R.color.ffffffff),
                          ),
                        ),
                      ],
                    ),
                  ),
                  Visibility(
                    visible: topic.status.actions.isNotEmpty ||
                        topic.status.extraActions.isNotEmpty,
                    child: Container(
                        child: Column(
                      children: [
                        Container(
                          margin: EdgeInsets.only(
                              top: R.dimen.dp20, bottom: R.dimen.dp10),
                          child: Divider(),
                        ),
                        Container(
                          child: Wrap(
                            alignment: WrapAlignment.start,
                            spacing: R.dimen.dp16,
                            runSpacing: R.dimen.dp12,
                            children: [
                              for (TopicAction a in topic.status.actions)
                                Stack(
                                  children: [
                                    Container(
                                      decoration: BoxDecoration(
                                        borderRadius:
                                            BorderRadius.circular(R.dimen.sp20),
                                        color: ColorKit.fromHex(a.color),
                                      ),
                                      padding: EdgeInsets.symmetric(
                                          horizontal: R.dimen.dp24,
                                          vertical: R.dimen.dp5),
                                      child: Text(
                                        "${a.name}",
                                        style: TextStyle(
                                            fontSize: R.dimen.sp13,
                                            color: R.color.ffffffff),
                                      ),
                                    ),
                                    Positioned(
                                        right: 0,
                                        child: Visibility(
                                          visible:
                                              a == TopicAction.leaveMessage &&
                                                  topic.messageCount > 0,
                                          child: Container(
                                            width: R.dimen.dp13,
                                            height: R.dimen.dp13,
                                            alignment: Alignment.center,
                                            decoration: BoxDecoration(
                                                shape: BoxShape.circle,
                                                color: R.color.ffad1d47),
                                            child: Text(
                                              "${topic.messageCount}",
                                              style: TextStyle(
                                                  fontSize: R.dimen.sp9,
                                                  color: R.color.ffffffff),
                                            ),
                                          ),
                                        ))
                                  ],
                                )
                            ],
                          ),
                        ),
                        Container(
                          child: Row(
                            children: [
                              for (TopicExtraAction a
                                  in topic.status.extraActions)
                                Expanded(
                                  flex: a == TopicExtraAction.viewIllegalReason
                                      ? 2
                                      : 1,
                                  child: Row(
                                    mainAxisAlignment: MainAxisAlignment.center,
                                    children: [
                                      Expanded(
                                          child: Row(
                                        mainAxisAlignment:
                                            MainAxisAlignment.center,
                                        children: [
                                          Image.asset(a.icon),
                                          Container(
                                            margin: EdgeInsets.only(
                                                left: R.dimen.dp6),
                                            child: Text(
                                              a.name,
                                              style: TextStyle(
                                                  color:
                                                      ColorKit.fromHex(a.color),
                                                  fontSize: R.dimen.sp13),
                                            ),
                                          ),
                                        ],
                                      )),
                                      Container(
                                        width: .5,
                                        height: R.dimen.dp14,
                                        color: R.color.ffcccccc,
                                      )
                                    ],
                                  ),
                                )
                            ],
                          ),
                        ),
                        Visibility(
                          visible: topic.dateVisibile,
                          child: Container(
                            margin: EdgeInsets.only(top: R.dimen.dp20),
                            padding:
                                EdgeInsets.symmetric(horizontal: R.dimen.dp16),
                            child: DefaultTextStyle(
                              style: TextStyle(
                                  fontSize: R.dimen.sp12,
                                  color: R.color.ff666666),
                              child: Row(
                                mainAxisAlignment:
                                    MainAxisAlignment.spaceBetween,
                                children: [
                                  Text("首次发布：${topic.createAt}"),
                                  Text("最后更新：${topic.updateAt}"),
                                ],
                              ),
                            ),
                          ),
                        ),
                      ],
                    )),
                  )
                ],
              ),
            );
          }, childCount: controller.topics.length))
        ],
      ),
    );
  }
}
